﻿using MediatR;
using SmartMedicalCare.API.Write.Applications.Commands.二级科室;
using SmartMedicalCare.Domain;
using SmartMedicalCare.ErronCode;
using SmartMedicalCare.Infrastructure.Implaction;

namespace SmartMedicalCare.API.Write.Applications.CommandHandlers.二级科室
{
    public class UpdateDeptSubCategoryCommandHandler : IRequestHandler<UpdateDeptSubCategoryCommand, APIResult<int>>
    {
        private readonly IBaseRespository<DeptSubCategoryModel> depRep;

        public UpdateDeptSubCategoryCommandHandler(IBaseRespository<DeptSubCategoryModel> depRep)
        {
            this.depRep = depRep;
        }
        public async Task<APIResult<int>> Handle(UpdateDeptSubCategoryCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            result.code=ResultCode.修改成功;
            result.Message=ResultCode.修改成功.ToString();

            var res=depRep.GetAll().FirstOrDefault(x=>x.DeptSubCategoryId==request.DeptSubCategoryId);
            res.Status=request.Status;
            res.Name=request.Name;
            res.DepartmentId=request.DepartmentId;
            res.Intro=request.Intro;
            await depRep.UpdateAsync(res);


            return  await Task.FromResult(result);
        }
    }
}
